package com.ls.mq.pubsub;

import java.util.Map;
import java.util.Set;

import com.ls.mq.iterface.MessageListener;

import redis.clients.jedis.JedisPubSub;

public class JedisPubSubListener extends JedisPubSub {
	
	/**
	 * channel 和监听者列表
	 */
	private Map<String, Set<MessageListener>> listenerMap;
	
	public JedisPubSubListener(Map<String, Set<MessageListener>> listenerMap){
		this.listenerMap=listenerMap;
	}
	
    public void onMessage(String channel, String message) {
    	Set<MessageListener> listeners = listenerMap.get(channel);
    	for(MessageListener l:listeners){
    		l.doMessage(channel, message);
    	}
    }

    public void onSubscribe(String channel, int subscribedChannels) {
    }

    public void onUnsubscribe(String channel, int subscribedChannels) {
    }

    public void onPSubscribe(String pattern, int subscribedChannels) {
    }

    public void onPUnsubscribe(String pattern, int subscribedChannels) {
    }

    public void onPMessage(String pattern, String channel,
        String message) {
    }
}